package com.hibase.common.entity;


import com.fasterxml.jackson.annotation.JsonInclude;
import com.hibase.common.constant.ResponseCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;

/**
 * WEB响应类
 *
 * @author HUFENG
 * @create 2017-12-13
 */
@Data
@SuppressWarnings({"rawtypes", "unchecked"})
@JsonInclude(JsonInclude.Include.NON_NULL)
@EqualsAndHashCode(callSuper = false)
public class ResponseModel<T> extends BaseResponseModel implements Serializable {

    /**
     * @Fields serialVersionUID : TODO
     */
    private static final long serialVersionUID = 4527286103414616167L;
    /**
     * 数据
     */
    private T data;

    private String msgDetail;

    private ResponseModel() {
        this(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage());
    }

    private ResponseModel(T data) {
        this(data, ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage());
    }

    private ResponseModel(int code, String message) {
        this(null, code, message);
    }

    private ResponseModel(T data, int code, String message) {
        this(data, code, message, null);
    }

    private ResponseModel(T data, int code, String message, String msgDetail) {
        super(code, message);
        this.data = data;
        this.msgDetail = msgDetail;
    }

    /**
     * 返回成功
     *
     * @return
     */
    public static ResponseModel successMsg() {
        return new ResponseModel();
    }

    /**
     * 返回成功，自定义状态码
     *
     * @return
     */
    public static ResponseModel successMsg(Object data) {
        return new ResponseModel(data);
    }

    /**
     * 返回成功，自定义状态码
     *
     * @return
     */
    public static ResponseModel successMsg(String msg, Object data) {
        return new ResponseModel(data, ResponseCode.SUCCESS.getCode(), msg);
    }

    /**
     * 返回成功，自定义状态码
     *
     * @return
     */
    public static ResponseModel failMsg() {
        return new ResponseModel(null, ResponseCode.SERVER_ERROR.getCode(), ResponseCode.SERVER_ERROR.getMessage());
    }

    /**
     * 返回成功，自定义状态码
     *
     * @return
     */
    public static ResponseModel failMsg(String msg, String msgDetail, Object data) {
        return new ResponseModel(data, ResponseCode.SERVER_ERROR.getCode(), msg, msgDetail);
    }

    /**
     * 返回成功，自定义状态码
     *
     * @return
     */
    public static ResponseModel failMsg(String msg, Object data) {
        return new ResponseModel(data, ResponseCode.SERVER_ERROR.getCode(), msg);
    }

    /**
     * 返回成功，自定义状态码
     *
     * @return
     */
    public static ResponseModel failMsg(int code, String msg) {
        return new ResponseModel(null, code, msg);
    }

    /**
     * 返回成功，自定义状态码
     *
     * @return
     */
    public static ResponseModel failMsg(int code,String msgDetail, String msg) {
        return new ResponseModel(null, code, msg,msgDetail);
    }

    /**
     * 返回成功，自定义状态码
     *
     * @return
     */
    public static ResponseModel failMsg(Object data) {

        return new ResponseModel(data, ResponseCode.SERVER_ERROR.getCode(), ResponseCode.SERVER_ERROR.getMessage());

    }
}
